package com.hiof.servercommunication.background.job.managers;

import com.hiof.servercommunication.background.job.GetAthleteLatestLocationJob;
import com.hiof.servercommunication.background.job.LiveLocationSendJob;
import com.hiof.servercommunication.background.job.TimerJobManager;
import com.hiof.servercommunication.background.job.listener.IAthletesLatestLocationReceiveListener;
import com.hiof.servercommunication.background.job.listener.IListener;

/**
 * Created by IntelliJ IDEA.
 * User: manish
 * Date: 4/1/12
 * Time: 12:19 PM
 * To change this template use File | Settings | File Templates.
 */
public class SupportBackgroundThreadManager extends AbstractBackgroundThreadManager {

    private static SupportBackgroundThreadManager supportBackgroundManager = new SupportBackgroundThreadManager();
    protected LiveLocationSendJob liveLocationSendJob;
    private GetAthleteLatestLocationJob getAthleteLatestLocationJob;
    private TimerJobManager timerJobManager;

    private SupportBackgroundThreadManager() {
        timerJobManager = TimerJobManager.getInstance();
        liveLocationSendJob = new LiveLocationSendJob();
        getAthleteLatestLocationJob = new GetAthleteLatestLocationJob();
    }

    public static SupportBackgroundThreadManager getInstance() {
        return supportBackgroundManager;
    }


    @Override
    public void setUp() {
        timerJobManager.addTimerJob(liveLocationSendJob);
        timerJobManager.addTimerJob(getAthleteLatestLocationJob);
    }

    @Override
    public void registerListener(IListener listener) {
        if(listener instanceof LiveLocationSendJob){
            liveLocationSendJob.addListener(listener);
        } else if(listener instanceof IAthletesLatestLocationReceiveListener){
            getAthleteLatestLocationJob.addListener(listener);
        }
    }

    @Override
    public void removeListener(IListener listener) {
        if(listener instanceof LiveLocationSendJob){
            liveLocationSendJob.removeListener(listener);
        } else if(listener instanceof IAthletesLatestLocationReceiveListener){
            getAthleteLatestLocationJob.removeListener(listener);
        }
    }
}
